if (!requestScreenCapture()) {
  toastLog("请求截图权限失败");
  exit();
}

var captureImg = captureScreen();
var ocrResult = paddle.ocr(captureImg);
// var ocrResult = gmlkit.ocr(captureImg, "zh").toArray(3);
// console.log(ocrResult);
logText();
// clickText(["今日已完成"]);

// console.log(
//   !!(textStartsWith("首页").findOne() && textStartsWith("发现").findOne())
// );

function logText() {
  for (index = 0; index < ocrResult.length; index++) {
    var item = ocrResult[index];
    console.log(item.confidence, item.text);
  }
}
function clickText(content) {
  if (!Array.isArray(content)) {
    content = [content];
  }
  for (index = 0; index < ocrResult.length; index++) {
    var item = ocrResult[index];
    if (content.some((x) => item.text == x)) {
      console.log(item);
      var bounds = item.bounds;
      click(bounds.centerX(), bounds.centerY());
      return;
    }
  }
}
